// pages/my/myTradingRecord/myTradingRecord.js
const App = getApp();
const utils = require('../../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:0,
    hasMoreData:true,
    list:[],
    key:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserInfo();
    if (options.type == 0) {
      this.setData({
        key:'提取'
      })
    }
    this.recordList();
  },
  //获取个人信息
  getUserInfo:function (){
    utils.requestUrl({
      url:'/niu/api/weibo_getuserinfo.php',
      params: {
        markid:wx.getStorageSync('markId'),
        userid:wx.getStorageSync('userId')
      }
    }).then((res) =>{
      console.log(res.data);
      let data = res.data;
      this.setData({
        faceurl:data.faceurl,
        nick:data.nick,
      })
    })
  },
  recordList:function (){
    let that = this;
    let page = that.data.page;
    let key = that.data.key
    utils.requestUrl({
      url:'/niu/apiv3/xiandanv3_mymoneyrmb.php?method=list',
      params:{
        markid:wx.getStorageSync('markId'),
        key:key,
        page:page
      }
    }).then((res) =>{
      console.log(res);
      var contentListTem = that.data.list;
        if (res.data.datacount == 0 || res.data.datacount == null) {
          that.setData({
            noContent:true,
          })
        }else{
          that.setData({
            noContent:false
          })
        }
        if (res.data.datacount > 0) {
          var contentList = res.data.data
          
          contentList.forEach((item) => {
            //这里需要截取的内容
            item.subTime = utils.subTime(item.time)
          })
          if (contentList.length < res.data.pagesize) {
            that.setData({
              list:contentListTem.concat(contentList),
              hasMoreData: false
            })
          }else{
            that.setData({
              list: contentListTem.concat(contentList),
              hasMoreData: true,
              page: page + 1
          })
          }
        }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})